export default () => ({
  port: parseInt(process.env.PORT || '3000', 10),
  database: {
    url: process.env.DATABASE_URL || '',
  },
  jwt: {
    secret: process.env.JWT_SECRET || '',
    expiresIn: process.env.JWT_EXPIRES_IN || '7d',
  },
  google: {
    clientId: process.env.GOOGLE_CLIENT_ID || '',
  },
  tencentCloud: {
    cos: {
      secretId: process.env.TENCENT_CLOUD_SECRET_ID || '',
      secretKey: process.env.TENCENT_CLOUD_SECRET_KEY || '',
      bucket: process.env.TENCENT_CLOUD_COS_BUCKET || '',
      region: process.env.TENCENT_CLOUD_COS_REGION || 'ap-beijing',
    }
  },
  environment: process.env.NODE_ENV || 'development',
  isDevelopment: process.env.NODE_ENV === 'development',
  isProduction: process.env.NODE_ENV === 'production',
});

// 配置验证函数
export const validateConfig = () => {
  const requiredEnvVars = [
    'DATABASE_URL',
    'JWT_SECRET',
  ];

  const missingVars = requiredEnvVars.filter(varName => !process.env[varName]);
  
  if (missingVars.length > 0) {
    throw new Error(`缺少必要的环境变量: ${missingVars.join(', ')}`);
  }

  // 检查腾讯云COS配置（可选）
  const cosVars = [
    'TENCENT_CLOUD_SECRET_ID',
    'TENCENT_CLOUD_SECRET_KEY', 
    'TENCENT_CLOUD_COS_BUCKET',
    'TENCENT_CLOUD_COS_REGION'
  ];
  
  const missingCosVars = cosVars.filter(varName => !process.env[varName]);
  
  if (missingCosVars.length > 0) {
    console.warn(`腾讯云COS配置不完整，文件上传功能将使用临时URL: ${missingCosVars.join(', ')}`);
  }
};
